#include "../include/Equipment.hh"
#include "../include/Character.hh"
#include <iostream>

Equipment::Equipment(const std::string& name, const std::string& desc, EquipmentType type, int level)
    : name(name), description(desc), type(type), level(level) {
    setBonuses();
}

void Equipment::applyBonuses(Character& character) const {
    character.attributes.health += bonuses.health;
    character.maxHealth += bonuses.health; // Increase max health
    character.attributes.attack += bonuses.attack;
    character.attributes.defense += bonuses.defense;
    character.attributes.critChance += bonuses.critChance;
    character.attributes.critDamage += bonuses.critDamage;
    character.attributes.speed += bonuses.speed;
    character.attributes.armor += bonuses.armor;
    character.attributes.penetration += bonuses.penetration;
    character.attributes.damageMultiplier += bonuses.damageMultiplier - 1.0f;
}

void Equipment::upgrade() {
    if (level < MAX_LEVEL) {
        ++level;
        setBonuses();
        std::cout << name << " has been upgraded to level " << level << "!\n";
    }
}

void Equipment::setBonuses() {
    bonuses = AttributeBonuses();
    switch (type) {
        case EquipmentType::WEAPON:
            bonuses.attack = 10 * level * pow(2, (level - 1));
            bonuses.critChance = 10 * level * pow(2, (level - 1));
            break;
        case EquipmentType::HELMET:
            bonuses.health = 50 * level * pow(2, (level - 1));
            bonuses.defense = 5 * level * pow(2, (level - 1));
            break;
        case EquipmentType::ARMOR:
            bonuses.health = 100 * level * pow(2, (level - 1));
            bonuses.armor = 10 * level * pow(2, (level - 1));
            break;
        case EquipmentType::LEGGINGS:
            bonuses.health = 30 * level * pow(2, (level - 1));
            bonuses.defense = 8 * level * pow(2, (level - 1));
            bonuses.speed = 5 * level * pow(2, (level - 1));
            break;
        case EquipmentType::BOOTS:
            bonuses.health = 20 * level * pow(2, (level - 1));
            bonuses.speed = 10 * level * pow(2, (level - 1));
            bonuses.penetration = 5 * level * pow(2, (level - 1));
            break;
        case EquipmentType::ACCESSORY:
            bonuses.critChance = 10 * level * pow(2, (level - 1));
            bonuses.critDamage = 5 * level * pow(2, (level - 1));
            break;
    }
}